package ntu.sna;

public class LifeGenerator {
	private static short[] chooseZone = new short[5000];
	private static int zoneSize;
	private static double[] lifeDisTW = new double[]{
			0.00596006
			,0.000780008
			,0.000550006
			,0.000390004
			,0.000300003
			,0.000250003
			,0.000240002
			,0.000230002
			,0.000220002
			,0.000200002
			,0.000200002
			,0.000200002
			,0.000220002
			,0.000260003
			,0.000340003
			,0.000450005
			,0.000580006
			,0.000690007
			,0.000750008
			,0.000740007
			,0.000720007
			,0.000720007
			,0.000740007
			,0.000770008
			,0.000790008
			,0.000800008
			,0.000830008
			,0.000880009
			,0.000940009
			,0.00099001
			,0.001060011
			,0.001130011
			,0.001220012
			,0.001320013
			,0.001410014
			,0.001510015
			,0.001630016
			,0.001760018
			,0.001890019
			,0.00201002
			,0.002160022
			,0.002320023
			,0.002510025
			,0.002700027
			,0.002870029
			,0.003070031
			,0.003270033
			,0.003440034
			,0.003590036
			,0.003780038
			,0.004090041
			,0.004440044
			,0.004820048
			,0.005270053
			,0.005830058
			,0.006400064
			,0.006890069
			,0.007360074
			,0.007840078
			,0.008320083
			,0.008870089
			,0.009600096
			,0.010440104
			,0.011310113
			,0.012230122
			,0.013220132
			,0.014330143
			,0.015520155
			,0.016710167
			,0.017870179
			,0.019070191
			,0.020320203
			,0.021610216
			,0.022930229
			,0.024290243
			,0.025650257
			,0.02697027
			,0.028210282
			,0.029350294
			,0.030410304
			,0.031360314
			,0.032120321
			,0.032630326
			,0.032850329
			,0.032760328
			,0.032370324
			,0.031700317
			,0.030870309
			,0.029720297
			,0.028270283
			,0.026540265
			,0.024560246
			,0.022370224
			,0.0200202
			,0.017580176
			,0.015120151
			,0.012710127
			,0.010420104
			,0.008310083
			,0.006440064
	};
	private static double[] ageDisTW = new double[]{
		0.076047
		,0.052517
		,0.063583
		,0.067626
		,0.066387
		,0.08151
		,0.082809
		,0.075398
		,0.078037
		,0.079587
		,0.073303
		,0.062555
		,0.038032
		,0.031908
		,0.026194
		,0.02071
		,0.0146
		,0.006636
		,0.002015
		,0.000466
	};
	
	static {
		int currentIndex = 0;
		for(int i = 0; i < lifeDisTW.length; i++){
			for(int j = 0; j < (int)(lifeDisTW[i] * chooseZone.length); j++){
				chooseZone[currentIndex] = (short)i;
				currentIndex++;
			}
		}
		zoneSize = currentIndex + 1;
	}
	
	public static int gen(){
		return chooseZone[(int)(zoneSize * Math.random())];
	}
	
	public static double getLifeDisTW(int index){
		return lifeDisTW[index];
	}
	
	public static double getAgeDisTW(int index){
		return ageDisTW[index / 5] / (double)5;
	}
}
